package com.example.intermediate_control;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;

/**
 * @param
 * @description 开关按钮
 * @return author snjgm
 * time 2022/7/13 下午4:08
 */
public class SwitchActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {

    private TextView switchView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_switch);
        switchView = findViewById(R.id.tv_Switch_Process);
        Switch sw_Checkbox = findViewById(R.id.switch_checkbox);

        sw_Checkbox.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        if (b) {
            switchView.setText("switch按钮开了");
        }else {
            switchView.setText("switch按钮关了");
        }
    }
}